#include <iostream>
#include <vector>
using namespace std;

class Solution {                                                      
public:
    int minimizeMax(vector<int>& nums, int p) {
        sort(nums.begin(), nums.end());
        auto check = [&](int mx) -> bool {
            int cnt = 0;
            for (int i = 0; i < nums.size() - 1; i++) {
                if (nums[i + 1] - nums[i] <= mx) {
                    cnt++;
                    i++;
                }
            }
            return cnt >= p;
        };
        int left = 0, right = nums.back() - nums[0];
        while (left < right) {
            int mid = (left + right) >> 1;
            if (check(mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
};
int main() {
    Solution solution;
    
    vector<int> nums = {10, 1, 2, 7, 1, 3};
    int p = 2;
    cout << "测试用例1: " << endl;
    cout << "数组: ";
    for (int num : nums1) cout << num << " ";
    cout << ", p = " << p << endl;
    cout << "最小化的最大差值: " << solution.minimizeMax(nums, p) << endl << endl;
}